﻿using System;
using System.Collections.Generic;
 
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manageweb_Stock_StockBalance : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"] == null)
        {
            Response.Redirect("~/MemberLogin.aspx");
        }
        BindBalance();
    }
    protected void GV_StockBalance_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        this.GV_StockBalance.PageIndex = e.NewPageIndex;
        BindBalance();
    }

    protected void BindBalance()
    { 
        SQLExpressDAL.DealRecord obj = new SQLExpressDAL.DealRecord();
        this.GV_StockBalance.DataSource= obj.GetStockBalance(Session["UserID"].ToString(), this.txtBeginDate.Text, this.txtEndDate.Text);
        this.GV_StockBalance.DataBind();
    }

    decimal buyCount = 0.0m;
    decimal daiguCount = 0.0m;
    decimal saleCount = 0.0m;
    decimal holdCount = 0.0m;
    decimal chengbenCount = 0.0m;
    decimal shijiaCount = 0.0m;
    decimal lirunCount = 0.0m;

    protected void GV_StockBalance_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            buyCount += Convert.ToDecimal(e.Row.Cells[2].Text);
            daiguCount += Convert.ToDecimal(e.Row.Cells[3].Text);
            saleCount += Convert.ToDecimal(e.Row.Cells[4].Text);
            holdCount += Convert.ToDecimal(e.Row.Cells[5].Text);

            Label chengben = e.Row.FindControl("lblChengBen") as Label;
            chengbenCount += Convert.ToDecimal(string.IsNullOrEmpty(chengben.Text) ? "0.00" : chengben.Text);

           
            shijiaCount += Convert.ToDecimal(string.IsNullOrEmpty(e.Row.Cells[8].Text) ? "0.00" : e.Row.Cells[8].Text);

            Label liRun = e.Row.FindControl("lblLiRun") as Label;
            lirunCount += Convert.ToDecimal(string.IsNullOrEmpty(liRun.Text) ? "0.00" : liRun.Text);
        }
        else if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[2].Text = buyCount.ToString();
            e.Row.Cells[3].Text = daiguCount.ToString();
            e.Row.Cells[4].Text = saleCount.ToString();
            e.Row.Cells[5].Text = holdCount.ToString();
            e.Row.Cells[7].Text = chengbenCount.ToString();
            e.Row.Cells[8].Text = shijiaCount.ToString();
            e.Row.Cells[9].Text = lirunCount.ToString();
          
            e.Row.Cells[2].Style.Add(HtmlTextWriterStyle.TextAlign, "right");
        }
    }
    protected void btnQuery_Click(object sender, EventArgs e)
    {

    }
}
